import wx;
import wx.adv;

class HelloFrame(wx.Frame):
  
  def __init__(self, *args, **kw):
    super(HelloFrame, self).__init__(*args, **kw);

    icon = wx.Icon("cl.ico", wx.BITMAP_TYPE_ICO);
    self.SetIcon(icon);
    self.SetIcons

    pnl = wx.Panel(self);
    st = wx.StaticText(pnl, label="Hello world!", pos=(25, 25));
    font = st.GetFont();
    font.PointSize = 14;
    font = font.Bold();
    st.SetFont(font);

    self.makeMenuBar();
    self.CreateStatusBar();
    self.SetStatusText("welcome to tdx");

  def makeMenuBar(self):
    '''
    菜单栏
    '''
    fileMenu = wx.Menu();
    helloItem = fileMenu.Append(-1, "&hello\tCtrl-H", "你好");
    fileMenu.AppendSeparator();
    exitItem = fileMenu.Append(wx.ID_EDIT, "&退出", "退出");

    helpMenu = wx.Menu();
    aboutItem = helpMenu.Append(wx.ID_ABOUT);

    menuBar = wx.MenuBar();
    menuBar.Append(fileMenu, "&文件");
    menuBar.Append(helpMenu, "&帮助");
    self.SetMenuBar(menuBar);

    self.Bind(wx.EVT_MENU, self.onHello, helloItem);
    self.Bind(wx.EVT_MENU, self.onExit, exitItem);
    self.Bind(wx.EVT_MENU, self.onAbout, aboutItem);

  def onHello(self, event):
    wx.MessageBox("你好啊");

  def onExit(self, event):
    self.Close(True);

  def onAbout(self, event):
    wx.MessageBox("这是这个 dialog 的介绍", "关于", wx.OK|wx.ICON_INFORMATION);

class TbIcon(wx.adv.TaskBarIcon):
  def __init__(self):
    super(TbIcon, self).__init__();
    self.SetIcon(wx.Icon("cl.ico"));

    # 生成点击的 menu 菜单
    menu = wx.Menu();
    exitItem = menu.Append(wx.ID_EXIT, "&退出", "退出");
    self.menu = menu;

    self.Bind(wx.adv.EVT_TASKBAR_CLICK, self.onClick);
    self.Bind(wx.EVT_MENU, self.onExit, exitItem);

  def onClick(self, event):
    '''
    点击事件
    '''
    self.PopupMenu(self.menu);

  def onExit(self, event):
    wx.Exit();

if __name__ == "__main__":
  app = wx.App();
  frm = HelloFrame(None, title="webServer", size=wx.Size(800, 500));
  frm.CentreOnScreen();
  frm.Show();

  # 任务栏图标
  tbIcon = TbIcon();

  app.MainLoop();